home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------
- wrap events.c Watch keyboard events to do
- word wrapping, and watch mouse
- events to handle clicks in the
- wrap icon.
-
- THINK C "Set Project Type..." settings:
- code resource, type 'OAPe', ID 1000,
- custom header, preloaded and locked,
- file type 'rsrc', file creator 'RSED'.
- ---------------------------------------------
- */
- #include <Script.h>
- #include "defs.h"
- void main( EventRecord *evt );
-
- #define RETURN_MESSAGE 0x0002240DL
- #define WRAP_FACTOR 10
- #define SCROLLBAR_WIDTH 16
- #define MODIFIER_KEYS 0x1F00
-
- void main( EventRecord *evt )
- {
- WindowPeek front;
- Wrap_info **wrap_info;
- Rect icon_rect;
- RgnHandle redraw_rgn;
- GrafPtr save_port;
- short wrap_margin, font_size;
-
- wrap_info = (Wrap_info **)
- GetResource( 'OAP1', 128 );
- if (wrap_info == NIL)
- return;
- front = (WindowPeek) FrontWindow();
-
- if ( (evt->what == keyDown) &&
- ((evt->message & charCodeMask) == ' ') &&
- ((evt->modifiers & MODIFIER_KEYS) == 0) &&
- ((**wrap_info).wrap) )
- {
- font_size = front->port.txSize;
- if (font_size == 0)
- font_size = GetDefFontSize();
- wrap_margin = font_size * WRAP_FACTOR
- + SCROLLBAR_WIDTH;
- if ( (**wrap_info).last_insertion_point >
- front->port.portRect.right - wrap_margin )
- {
- (**wrap_info).last_insertion_point = 0;
- evt->message = RETURN_MESSAGE;
- }
- } // end if keyDown && space
-
- else if (evt->what == mouseDown)
- {
- /*
- If the click was in our little icon in the
- window's title bar, then toggle the wrapping
- state.
- */
- icon_rect = (**(front->strucRgn)).rgnBBox;
- icon_rect.left += 22;
- icon_rect.top += 6;
- icon_rect.right = icon_rect.left + 8;
- icon_rect.bottom = icon_rect.top + 8;
-
- if (PtInRect( evt->where, &icon_rect ))
- {
- evt->what = nullEvent;
- (**wrap_info).wrap = !(**wrap_info).wrap;
- ChangedResource( (Handle) wrap_info );
-
- redraw_rgn = NewRgn();
- RectRgn( redraw_rgn, &icon_rect );
- GetPort( &save_port );
- PaintOne( front, redraw_rgn );
- SetPort( save_port );
- DisposeRgn( redraw_rgn );
- }
- } // end if mouseDown
-
- }
-